/* 
	该文件内容不要轻易的手动更改，除非你知道你在干什么。 
*/
#ifndef _VAR_HPP
#define _VAR_HPP

#define BIT31	0x80000000
#define BIT30	0x40000000
#define BIT29	0x20000000
#define BIT28	0x10000000
#define BIT27	0x08000000
#define BIT26	0x04000000
#define BIT25	0x02000000
#define BIT24	0x01000000
#define BIT23	0x00800000
#define BIT22	0x00400000
#define BIT21	0x00200000
#define BIT20	0x00100000
#define BIT19	0x00080000
#define BIT18	0x00040000
#define BIT17	0x00020000
#define BIT16	0x00010000
#define BIT15	0x00008000
#define BIT14	0x00004000
#define BIT13	0x00002000
#define BIT12	0x00001000
#define BIT11	0x00000800
#define BIT10	0x00000400
#define BIT9	0x00000200
#define BIT8	0x00000100
#define BIT7	0x00000080
#define BIT6	0x00000040
#define BIT5	0x00000020
#define BIT4	0x00000010
#define BIT3	0x00000008
#define BIT2	0x00000004
#define BIT1	0x00000002
#define BIT0	0x00000001


#if CONFIG_MODE == 0
	#define log(format, ...) {\
		printf("\033[36m%d - \033[33m", esp_log_timestamp());\
		printf(format, ##__VA_ARGS__);\
		printf("\n\033[36m[%s:%d]\033[m\n", __FILE__, __LINE__);\
	}
#else
	#define log(format, ...)
#endif


#if CONFIG_DISP_INFO == 0
	#define dispInitInfo(INFO) {printf(INFO); printf("\n");}
	#define dispInitInfo(INFO) printf("%s\n", INFO)
#else
	#define dispInitInfo(INFO) pageInfoAdd(INFO)
#endif

#define LOG_ERR(F) {if(F != ESP_OK) {log(esp_err_to_name(F))}}

// ui目录的相对路径
#define CFONT_FILE	"font/cfont_1.c"
#define CFONT		&cfont_1

// 页面
#define PAGE_INFO		0
#define PAGE_HOME		1
#define PAGE_SETTINGS	2
#define PAGE_CNT		3

#define DELAY(T)		vTaskDelay(pdMS_TO_TICKS(T))
#define TT 				(1000 / CONFIG_FREERTOS_HZ)
#define MEM_UNIT		(512)

#define LVMT			xSemaphoreTake(lvMutex, portMAX_DELAY)
#define LVMG			xSemaphoreGive(lvMutex)



/*
	任务组
	0 屏幕初始化完成
	1 WIFI连接成功
	2 WIFI断开连接
	3 WIFI获取到IP
	4 WIFI AP开启完成
	5 WIFI AP停止
	6 WebSockets连接成功
	7 WebSockets断开连接
	8 WebSockets服务器关闭
*/
// 事件 - 屏幕初始化完成
#define EVENT_SCREEN_INIT_DONE		BIT0
// 事件 - WIFI连接成功
#define EVENT_WIFI_CONNECTED		BIT1
// 事件 - WIFI断开连接
#define EVENT_WIFI_DISCONNECTED		BIT2
// 事件 - WIFI获取到IP
#define EVENT_WIFI_GOT_IP			BIT3
// 事件 - AP开启完成
#define EVENT_WIFI_AP_START			BIT4
// 事件 - WIFI AP 停止
#define EVENT_WIFI_AP_STOP			BIT5
// 事件 - WebSocket连接成功
#define EVENT_WS_CONNECTED			BIT6
// 事件 - WebSocket断开连接
#define EVENT_WS_DISCONNECTED		BIT7
// 事件 - WebSocket服务器关闭
#define EVENT_WS_CLOSED				BIT8

// 图标
#define ICON_WIFI			"\xEE\xAF\x91"
#define ICON_WEBSOCKET		"\xEE\x9B\xA1"
#define ICON_USER			"\xEE\x98\xBE"

EventGroupHandle_t eventGroup;
QueueHandle_t wsDataQ;
QueueHandle_t inputQ;
TaskHandle_t wsSendOpH;
SemaphoreHandle_t lvMutex;

/* 
	SETTINGS 
*/

#define ST_USE_NET			0
#define ST_SSID				1
#define ST_PASSWORD			2
#define ST_CALL_SIGN		3
#define ST_KEY_TYPE			4
#define ST_KEY_INVERT		5
#define ST_DI_TIME			6
#define ST_PLAY_DI_TIME		7
#define ST_AUTO_SEND_TIME	8
#define ST_TRAN_CODE		9
#define ST_BEE_FREQ			10
#define ST_BEE_DUTY			11
#define ST_WS_URL			12
#define ST_WS_PORT			13
#define ST_WS_PATH			14

#define ST_CNT				15


typedef struct settingItem {
	char *itemName;
	char strValue[64];
	char defaultStrValue[64];
	uint32_t intValue;
	uint32_t defaultIntValue;
	char *valueType;
} settingItem_t;

settingItem_t stGroup[] = {
	{"useNet", "", "", 1, 1, "int"},
    {"ssid", "", "", 0, 0, "str"}, 
    {"password", "", "", 0, 0, "str"},
	{"callSign", "ZClub", "ZClub", 0, 0, "str"},
	{"keyType", "", "", 0, 0, "int"},
	{"keyInvert", "", "", 0, 0, "int"},
	{"diTime", "", "", 110, 110, "int"},
	{"playDiTime", "", "", 80, 80, "int"},
	{"autoSendTime", "", "", 1000, 1000, "int"},
	{"tranCode", "", "", 0, 0, "int"},
	{"beeFreq", "", "", 800, 800, "int"},
	{"beeDuty", "", "", 4000, 4000, "int"},
	{"wsUrl", "ws://coffee.zclub.cool/ws", "ws://coffee.zclub.cool/ws", 0, 0, "str"},
	{"wsPort", "", "", 9013, 9013, "int"},
	{"wsPath", "coffee", "coffee", 0, 0, "str"}
};

typedef struct {
	lv_color_t bgColor;
	char *title;
	char *content;
	bool enable_0;
	bool enable_1;
	bool enable_2;
	char *text_0;
	char *text_1;
	char *text_2;
	void *fun_0;
	void *fun_1;
	void *fun_2;
} note_t;

// 输入内容与显示的输入内容
char *inputCode[512] = {0};

char apIpStr[25];
char staIpStr[25];

esp_err_t err;

// 电键使用的函数
// void (*keyFn)() = NULL;

#endif